package com.kingyea.mobilepolice.config.activemq;

import com.kingyea.mobilepolice.util.GlobalVar;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.listener.DefaultMessageListenerContainer;

import javax.jms.ConnectionFactory;
import javax.jms.Destination;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description
 * @date Created in 2018/4/24 19:26
 */
@Configuration
public class Config {


    /**
     * 设置外网队列 token消息 监听器，主动把token消息推送到内网
     *
     * @param connectionFactory
     * @return org.springframework.jms.listener.DefaultMessageListenerContainer
     * @author Mr.Lin
     * @date 2018/4/25 0:31
     */
    @Bean
    public DefaultMessageListenerContainer listenerContainer_wai(ConnectionFactory connectionFactory) {
        System.out.println(GlobalVar.inside);
        if (GlobalVar.inside.intValue() == GlobalVar.insideWai) {
            DefaultMessageListenerContainer m = new DefaultMessageListenerContainer();
            m.setConnectionFactory(connectionFactory);
            Destination d = new ActiveMQQueue(GlobalVar.MQ_SUBJECT_TOKEN);//*表示通配所有队列名称
            m.setDestination(d);
            m.setMessageListener(new SyncTokenMessageListener_wai());
            return m;
        }
        return null;
    }


}
